<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Package_option_entity{
	var $id = 0;
	var $language_id = 0;
	var $code = 0;
	var $package = "";
	var $price = 0;
	var $apply_period = 0;	
	var $CI;
	var $current_dbprefix = "";
	
	function __construct() {
		$this->CI= & get_instance();
		$this->current_dbprefix = $this->CI->db->dbprefix;
		$this->CI->db->set_dbprefix('default_');
	}
	function __destruct() {
		$this->CI->db->set_dbprefix($this->current_dbprefix);
	}
	function setId($input){
		$this->id=$input;
	}
	function setLanguageId($input){
		$this->language_id =$input;
	}
	function setCode($input){
		$this->code =$input;
	}
	function setPackage($input){
		$this->package =$input;
	}
	function setPrice($input){
		$this->price =$input;
	}
	function setApplyPeriod($input){
		$this->apply_period =$input;
	}
	function getId(){
		return $this->id;
	}
	function getLanguageId(){
		return $this->language_id;
	}
	function getCode(){
		return $this->code;
	}
	function getPackage(){
		return $this->package;
	}
	function getPrice(){
		return $this->price;
	}
	function getApplyPeriod(){
		return $this->apply_period;
	}
	
	function init($cmd, $input)
	{
		$this->CI->db->set_dbprefix('default_');
		
		if($cmd == 'id'){
			$result = $this->CI->db->where('id',$input)->get(TBL_PACKAGE_OPTION)->result();
		}else if($cmd == 'language_id'){
			$result = $this->CI->db->where('language_id',$input)->get(TBL_PACKAGE_OPTION)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->language_id = $result[0]->language_id;
			$this->code = $result[0]->code;
			$this->package = $result[0]->package;
			$this->price = $result[0]->price;
			$this->apply_period = $result[0]->apply_period;
			return $this;
		}
		return false;
	}
	function getPackaggOptionByCode($code){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->where('code',$code);
		return $this->CI->db->get(TBL_PACKAGE_OPTION)->result();
	}
	function getPackageOptionList(){
		$this->CI->db->set_dbprefix('default_');
		
		return $this->CI->db->get(TBL_PACKAGE_OPTION)->result();
	}
	function getPackageOptionByLanguage($language_id){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->where('language_id',$language_id);
		return $this->CI->db->get(TBL_PACKAGE_OPTION)->result();
	}
	function save(){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->set('language_id',$this->getLanguageId());
		$this->CI->db->set('code',$this->getCode());
		$this->CI->db->set('package',$this->getPackage());
		$this->CI->db->set('price',$this->getPrice());
		$this->CI->db->set('apply_period',$this->getApplyPeriod());
		
		$this->CI->db->insert(TBL_PACKAGE_OPTION);
		return $this->CI->db->insert_id();
	}
	function update(){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->set('language_id',$this->getLanguageId());
		$this->CI->db->set('code',$this->getCode());
		$this->CI->db->set('package',$this->getPackage());
		$this->CI->db->set('price',$this->getPrice());
		$this->CI->db->set('apply_period',$this->getApplyPeriod());
		
		return $this->CI->db->where('id', $this->id)->update(TBL_PACKAGE_OPTION);
	}
	function delete($id){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->where('id',$id);
		$this->CI->db->delete(TBL_PACKAGE_OPTION);
	}
	function deleteByCode($code){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->where('code',$code);
		$this->CI->db->delete(TBL_PACKAGE_OPTION);
		return $this->CI->db->affected_rows();
	}
}